﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditDBColumnList.aspx.cs"
    Inherits="Sqls_EditDBColumnList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="style/default.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        html { overflow: auto; }
        #splitter { background-color: white; border: 1px solid #ccc; width: 100%; }
        #filetree { overflow: auto; padding: 0px 10px 10px 0px; min-width: 100px; }
        #fileinfo { min-width: 100px; overflow: auto; /* No margin or border allowed */ }
        .switch-bar { background: #E5E5E5 url(images/toggle.png) no-repeat scroll 0px center; width: 10px; cursor: pointer; }
    </style>

    <script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function()
        {
            $("#btnAdd").click(function()
            {
                var tmp = $("#tmp tbody").html();
                $(".gv1").append(tmp);
                $(".gv1").append(tmp);
                $(".gv1").append(tmp);
                $(".gv1").append(tmp);
                $(".gv1").append(tmp);

            });
            jQuery.RemoveRow = function(obj)
            {
                $(obj).parent().parent().remove();
            }
            $("#btnSave").click(function()
            {
                var str = "";
                $(".gv1 tr.lupai").each(function()
                {
                    var colname = $(this).find(".colname").val();
                    var coltype = $(this).find(".coltype").val();
                    var collength = $(this).find(".collength").val();
                    var allowdbnull = $(this).find(".allowdbnull").attr("checked") == false ? "0" : "1";
                    var ispk = $(this).find(".ispk").attr("checked") == false ? "0" : "1";
                    var isindex = $(this).find(".isindex").attr("checked") == false ? "0" : "1";
                    var defaultval = $(this).find(".defaultvalue").val();
                    var brief = encodeURIComponent($(this).find(".brief").val());
                    var px = 0;

                    var name = $(this).find(".hidcolname").val();
                    var type = $(this).find(".hidcoltype").val();
                    var length = $(this).find(".hidcollength").val();
                    var dbnull = $(this).find(".hidallowdbnull").val();
                    var oispk = $(this).find(".hidispk").val();
                    var oisindex = $(this).find(".hidisindex").val();
                    var odefaultval = $(this).find(".hiddefaultvalue").val();
                    var obrief = encodeURIComponent($(this).find(".hidbrief").val());
                    var opx = 0;
                    if (colname != "")
                    {
                        str += colname + "$" + name + "|" + coltype + "$" + type + "|" + collength + "$" + length + "|" + allowdbnull + "$" + dbnull + "|" + ispk + "$" + oispk + "|" + isindex + "$" + oisindex + "|" + defaultval + "$" + odefaultval + "|" + brief + "$" + obrief + "|" + px + "$" + opx + "^";
                    }

                });
                alert("fd");

                $.post("FileHandle.ashx?ac=altercols&" + Math.random(), { tbname: $("#hidtbname").val(), str: str }, function(res)
                {
                    if (res == "ok")
                    {
                        alert("保存成功!");
                    } else
                    {
                        alert(res);
                    }
                });
            });
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div style="padding: 0 5px;">
        <div style="background-color: #E5E5E5; color: #CC3300; padding: 4px; border: solid 1px #D1D1D1;
            border-bottom: 0;">
            <div>
                <input id="btnAdd" style="float: right;" value="添加字段" type="button" />
                当前位置：<a href="Default.aspx">数据表</a> ＞<%=hidtbname.Value%>的字段</div>
            <div class="nofloat">
            </div>
        </div>
        <div>
            <table id="splitter">
                <tbody>
                    <tr valign="top">
                        <td id="tdleft" style="width: 200px; overflow: auto;">
                            <div id="filetree">
                                <asp:ListBox ID="listTable" runat="server" Width="100%" Height="600px" Style="padding: 5px;
                                    border: solid 1px #f8f8f8; color: #333; line-height: 2.0" AutoPostBack="True"
                                    OnSelectedIndexChanged="listTable_SelectedIndexChanged"></asp:ListBox>
                            </div>
                        </td>
                        <td class="switch-bar" onclick="$('#tdleft').toggle();">
                        </td>
                        <td>
                            <div id="fileinfo">
                                <div style="margin: 6px;">
                                    <div>
                                        <table class="gv1" cellspacing="0" cellpadding="0" rules="all" border="0" id="gvList"
                                            style="border-width: 0px; border-collapse: collapse;">
                                            <tr class="lup">
                                                <th scope="col">
                                                    字段名称
                                                </th>
                                                <th scope="col">
                                                    数据类型
                                                </th>
                                                <th scope="col">
                                                    长度
                                                </th>
                                                <th scope="col">
                                                    允许空
                                                </th>
                                                <th scope="col">
                                                    主键
                                                </th>
                                                <th scope="col">
                                                    索引
                                                </th>
                                                <th scope="col">
                                                    默认值
                                                </th>
                                                <th scope="col">
                                                    描述
                                                </th>
                                                <th scope="col">
                                                    操作
                                                </th>
                                            </tr>
                                            
                                        </table>
                                    </div>
                                    <div style="margin: 10px 0;">
                                        <input id="btnSave" type="button" value="保 存 修 改" /></div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="nofloat">
        </div>
    </div>
    <table id="tmp" style="display: none;">
        <tr class="lupai">
            <td>
                <input class="colname" style="width: 100px;" type="text" />
                <input class="hidcolname" type="hidden" />
            </td>
            <td>
                <select class="coltype" style="color: #6600FF;">
                    <option value="int">自动编号</option>
                    <option value="int">int</option>
                    <option value="nvarchar" selected="selected">nvarchar</option>
                    <option value="datetime">日期/时间[datetime]</option>
                    <option value="bit">是/否[bit]</option>
                    <option value="nvarchar">nvarchar(max)</option>
                    <option value="uniqueidentifier">uniqueidentifier</option>
                    <option value="varchar">varchar</option>
                    <option value="bigint">bigint</option>
                </select>
                <input class="hidcoltype" type="hidden" />
            </td>
            <td>
                <input class="collength" style="width: 50px;" value="50" type="text" />
                <input class="hidcollength" type="hidden" />
            </td>
            <td>
                <input type="checkbox" class="allowdbnull" checked="checked" />
                <input class="hidallowdbnull" type="hidden" />
            </td>
            <td>
                <input type="checkbox" class="ispk" value="" />
                <input class="hidispk" type="hidden" />
            </td>
            <td>
                <input type="checkbox" class="isindex" value="" />
                <input class="hidisindex" type="hidden" />
            </td>
            <td>
                <input class="defaultvalue" style="width: 80px;" type="text" />
                <input class="hiddefaultvalue" type="hidden" />
            </td>
            <td>
                <input class="brief" style="width: 150px;" type="text" />
                <input class="hidbrief" type="hidden" />
            </td>
            <td>
                <a href="javascript:" onclick="$.RemoveRow(this);">删除</a>
            </td>
        </tr>
    </table>
    <input type="hidden" id="hidtbname" runat="server" />
    <asp:Literal ID="litercopyright" runat="server"></asp:Literal>
    <asp:Button Style="display: none;" ID="btnRefresh" runat="server" Text="刷新列表" OnClick="btnRefresh_Click" />
    </form>
</body>
</html>
